home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / os2 / pmnos11s / ax25.h < prev    next >
C/C++ Source or Header  |  1992-10-31  |  12KB  |  352 lines

  1.  /* Mods by G1EMM */
  2. #ifndef    _AX25_H
  3. #define    _AX25_H
  4.  
  5. #ifndef    _GLOBAL_H
  6. #include "global.h"
  7. #endif
  8.  
  9. #ifndef _IP_H
  10. #include "ip.h"
  11. #endif
  12.  
  13. #ifndef    _MBUF_H
  14. #include "mbuf.h"
  15. #endif
  16.  
  17. #ifndef    _IFACE_H
  18. #include "iface.h"
  19. #endif
  20.  
  21. #ifndef    _SOCKADDR_H
  22. #include "sockaddr.h"
  23. #endif
  24.  
  25. /* AX.25 datagram (address) sub-layer definitions */
  26.  
  27. #define    MAXDIGIS    7    /* Maximum number of digipeaters */
  28. #define    ALEN        6    /* Number of chars in callsign field */
  29. #define    AXALEN        7    /* Total AX.25 address length, including SSID */
  30. #define    AXBUF        10    /* Buffer size for maximum-length ascii call */
  31.  
  32. #ifndef _LAPB_H
  33. #include "lapb.h"
  34. #endif
  35.  
  36. /* Bits within SSID field of AX.25 address */
  37. #define    SSID        0x1e    /* Sub station ID */
  38. #define    REPEATED    0x80    /* Has-been-repeated bit in repeater field */
  39. #define    E        0x01    /* Address extension bit */
  40. #define    C        0x80    /* Command/response designation */
  41.  
  42. /* Our AX.25 address */
  43. extern char Mycall[AXALEN];
  44.  
  45. /* List of AX.25 multicast addresses, e.g., "QST   -0" in shifted ASCII */
  46. extern char Ax25multi[][AXALEN];
  47. #define QSTCALL 0
  48. #define NODESCALL 1
  49. #define MAILCALL 2
  50. #define IDCALL 3
  51. /*currently not used in this code*/
  52. #define OPENCALL 4
  53. #define CQCALL 5
  54. #define BEACONCALL 6
  55. #define RMNCCALL 7
  56. #define ALLCALL 8
  57.  
  58.  
  59. extern int Digipeat;
  60. extern int Ax25mbox;
  61.  
  62. /* Number of chars in interface field. The involved definition takes possible
  63.  * alignment requirements into account, since ax25_addr is of an odd size.
  64.  */
  65. #define    ILEN    (sizeof(struct sockaddr) - sizeof(short) - AXALEN)
  66.  
  67. /* Socket address, AX.25 style */
  68. struct sockaddr_ax {
  69.     short sax_family;        /* 2 bytes */
  70.     char ax25_addr[AXALEN];
  71.     char iface[ILEN];        /* Interface name */
  72. };
  73.  
  74. /* Internal representation of an AX.25 header */
  75. struct ax25 {
  76.     char dest[AXALEN];        /* Destination address */
  77.     char source[AXALEN];        /* Source address */
  78.     char digis[MAXDIGIS][AXALEN];    /* Digi string */
  79.     int ndigis;            /* Number of digipeaters */
  80.     int nextdigi;            /* Index to next digi in chain */
  81.     int cmdrsp;            /* Command/response */
  82. };
  83.  
  84. /* C-bit stuff */
  85. #define    LAPB_UNKNOWN        0
  86. #define    LAPB_COMMAND        1
  87. #define    LAPB_RESPONSE        2
  88.  
  89. /* AX.25 routing table entry */
  90. struct ax_route {
  91.     struct ax_route *next;        /* Linked list pointer */
  92.     char target[AXALEN];
  93.     char digis[MAXDIGIS][AXALEN];
  94.     int ndigis;
  95.     char type;
  96. #define    AX_LOCAL    1        /* Set by local ax25 route command */
  97. #define    AX_AUTO        2        /* Set by incoming packet */
  98.     char mode;            /* Connection mode (G1EMM) */
  99. #define    AX_DEFMODE    0        /* Use default interface mode */
  100. #define    AX_VC_MODE    1        /* Try to use Virtual circuit */
  101. #define    AX_DATMODE    2        /* Try to use Datagrams only */
  102. };
  103. #define NULLAXR    ((struct ax_route *)0)
  104.  
  105. extern struct ax_route *Ax_routes;
  106. extern struct ax_route Ax_default;
  107.  
  108. /* AX.25 Level 3 Protocol IDs (PIDs) */
  109. #define PID_X25        0x01    /* CCITT X.25 PLP */
  110. #define    PID_SEGMENT    0x08    /* Segmentation fragment */
  111. #define PID_TEXNET    0xc3    /* TEXNET datagram protocol */
  112. #define    PID_LQ        0xc4    /* Link quality protocol */
  113. #define    PID_APPLETALK    0xca    /* Appletalk */
  114. #define    PID_APPLEARP    0xcb    /* Appletalk ARP */
  115. #define    PID_IP        0xcc    /* ARPA Internet Protocol */
  116. #define    PID_ARP        0xcd    /* ARPA Address Resolution Protocol */
  117. #define    PID_RARP    0xce    /* ARPA Reverse Address Resolution Protocol */
  118. #define    PID_NETROM    0xcf    /* NET/ROM */
  119. #define    PID_NO_L3    0xf0    /* No level 3 protocol */
  120.  
  121. #define    SEG_FIRST    0x80    /* First segment of a sequence */
  122. #define    SEG_REM        0x7f    /* Mask for # segments remaining */
  123.  
  124. #define    AX_EOL        "\r"    /* AX.25 end-of-line convention */
  125.  
  126. /* Link quality report packet header, internal format */
  127. struct lqhdr {
  128.     int16 version;        /* Version number of protocol */
  129. #define    LINKVERS    1
  130.     int32    ip_addr;    /* Sending station's IP address */
  131. };
  132. #define    LQHDR    6
  133. /* Link quality entry, internal format */
  134. struct lqentry {
  135.     char addr[AXALEN];    /* Address of heard station */
  136.     int32 count;        /* Count of packets heard from that station */
  137. };
  138. #define    LQENTRY    11
  139.  
  140. /* Link quality database record format
  141.  * Currently used only by AX.25 interfaces
  142.  */
  143. struct lq {
  144.     struct lq *next;
  145.     char addr[AXALEN];    /* Hardware address of station heard */
  146.     struct iface *iface;    /* Interface address was heard on */
  147.     int32 time;        /* Time station was last heard */
  148.     int32 currxcnt;    /* Current # of packets heard from this station */
  149.  
  150. #ifdef    notdef        /* Not yet implemented */
  151.     /* # of packets heard from this station as of his last update */
  152.     int32 lastrxcnt;
  153.  
  154.     /* # packets reported as transmitted by station as of his last update */
  155.     int32 lasttxcnt;
  156.  
  157.     int16 hisqual;    /* Fraction (0-1000) of station's packets heard
  158.              * as of last update
  159.              */
  160.     int16 myqual;    /* Fraction (0-1000) of our packets heard by station
  161.              * as of last update
  162.              */
  163. #endif
  164. };
  165. #define    NULLLQ    (struct lq *)0
  166.  
  167. extern struct lq *Lq;    /* Link quality record headers */
  168.  
  169. /* Structure used to keep track of monitored destination addresses */
  170. struct ld {
  171.     struct ld *next;    /* Linked list pointers */
  172.     char addr[AXALEN];/* Hardware address of destination overheard */
  173.     struct iface *iface;    /* Interface address was heard on */
  174.     int32 time;        /* Time station was last mentioned */
  175.     int32 currxcnt;    /* Current # of packets destined to this station */
  176. };
  177. #define    NULLLD    (struct ld *)0
  178.  
  179. extern struct ld *Ld;    /* Destination address record headers */
  180.  
  181. /* Codes for the open_ax25 call */
  182. #define    AX_PASSIVE    0
  183. #define    AX_ACTIVE    1
  184. #define    AX_SERVER    2    /* Passive, clone on opening */
  185.  
  186. /* Max number of fake AX.25 interfaces for RFC-1226 encapsulation */
  187. #define    NAX25        16
  188.  
  189. #define    AXHEARD_PASS    0    /* Log both src and dest callsigns */
  190. #define    AXHEARD_NOSRC    1    /* do not log source callsign */
  191. #define    AXHEARD_NODST    2    /* do not log destination callsign */
  192. #define    AXHEARD_NONE    3    /* do not log any callsign */
  193.  
  194. /* an call that should not be jump-started */
  195. struct no_js {
  196.     struct no_js *next;
  197.     char call[AXALEN];
  198. };
  199.  
  200. /* Per-connection link control block
  201.  * These are created and destroyed dynamically,
  202.  * and are indexed through a hash table.
  203.  * One exists for each logical AX.25 Level 2 connection
  204.  */
  205. struct ax25_cb {
  206.     struct ax25_cb *next;        /* Linked list pointers */
  207.  
  208.     struct iface *iface;        /* Interface */
  209.  
  210.     struct mbuf *txq;        /* Transmit queue */
  211.     struct mbuf *rxasm;        /* Receive reassembly buffer */
  212.     struct mbuf *rxq;        /* Receive queue */
  213.  
  214.     char local[AXALEN];        /* Addresses */
  215.     char remote[AXALEN];
  216.  
  217.     struct {
  218.         char rejsent;        /* REJ frame has been sent */
  219.         char remotebusy;    /* Remote sent RNR */
  220.         char rtt_run;        /* Round trip "timer" is running */
  221.         char retrans;        /* A retransmission has occurred */
  222.         char clone;        /* Server-type cb, will be cloned */
  223.         char rxd_I_frame;   /* I-frame received */
  224.     } flags;
  225.  
  226.     char reason;            /* Reason for connection closing */
  227. #define    LB_NORMAL    0        /* Normal close */
  228. #define    LB_DM        1        /* Received DM from other end */
  229. #define    LB_TIMEOUT    2        /* Excessive retries */
  230. #define LB_UNUSED    3        /* Link is redundant - unused */
  231.  
  232.     char response;            /* Response owed to other end */
  233.     char vs;            /* Our send state variable */
  234.     char vr;            /* Our receive state variable */
  235.     char unack;            /* Number of unacked frames */
  236.     int maxframe;            /* Transmit flow control level, frames */
  237.     int16 paclen;            /* Maximum outbound packet size, bytes */
  238.     int16 window;            /* Local flow control limit, bytes */
  239.     char proto;            /* Protocol version */
  240. #define    V1    1            /* AX.25 Version 1 */
  241. #define    V2    2            /* AX.25 Version 2 */
  242.     int16 pthresh;            /* Poll threshold, bytes */
  243.     unsigned retries;        /* Retry counter */
  244.     unsigned n2;            /* Retry limit */
  245.     int state;            /* Link state */
  246. #define    LAPB_DISCONNECTED    1
  247. #define LAPB_LISTEN        2
  248. #define    LAPB_SETUP        3
  249. #define    LAPB_DISCPENDING    4
  250. #define    LAPB_CONNECTED        5
  251. #define    LAPB_RECOVERY        6
  252.     struct timer t1;        /* Retry timer */
  253.     struct timer t3;        /* Keep-alive poll timer */
  254.     struct timer t4;        /* Link redundancy timer */
  255.     int32 rtt_time;            /* Stored clock values for RTT, ticks */
  256.     int rtt_seq;            /* Sequence number being timed */
  257.     int32 srt;            /* Smoothed round-trip time, ms */
  258.     int32 mdev;            /* Mean rtt deviation, ms */
  259.  
  260.     void (*r_upcall) __ARGS((struct ax25_cb *,int));    /* Receiver upcall */
  261.     void (*t_upcall) __ARGS((struct ax25_cb *,int));    /* Transmit upcall */
  262.     void (*s_upcall) __ARGS((struct ax25_cb *,int,int));    /* State change upcall */
  263.  
  264.     int user;            /* User pointer */
  265.  
  266.     int segremain;            /* Segmenter state */
  267.     int jumpstarted;    /* Was this one jumpstarted ? */
  268. #define KNOWN_LINK  1       /* incoming conn. is already known in cb list */
  269. #define NETROM_LINK 2       /* new connection to netrom interface call */
  270. #define ALIAS_LINK  4       /* new connection to alias call */
  271. #define CONF_LINK   8       /* new connection to conference call */
  272. #define IFACE_LINK  16      /* new connection to the interface call */
  273. #define NR4_LINK    32
  274. #define TELNET_LINK 64
  275. #define JUMPSTARTED 128     /* jumpstart was used */
  276. };
  277.  
  278. /* Linkage to network protocols atop ax25 */
  279. struct axlink {
  280.     int pid;
  281.     void (*funct) __ARGS((struct iface *,struct ax25_cb *,char *, char *,
  282.      struct mbuf *,int));
  283. };
  284. extern struct axlink Axlink[];
  285. #if defined(JOHAN)
  286. #define NAX25       16
  287. /* an call that should not be jump-started */
  288. struct no_js {
  289.     struct no_js *next;
  290.     char call[AXALEN];
  291. };
  292. #endif
  293. /* In ax25.c: */
  294. struct ax_route *ax_add __ARGS((char *,int,char digis[][AXALEN],int));
  295. int ax_drop __ARGS((char *));
  296. struct ax_route *ax_lookup __ARGS((char *));
  297. void axip_input __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,int rxbroadcast));
  298. void ax_recv __ARGS((struct iface *,struct mbuf *));
  299. int ax_send __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,int prec,
  300.     int del,int tput,int rel));
  301. int ax_output __ARGS((struct iface *iface,char *dest,char *source,int16 pid,
  302.     struct mbuf *data));
  303. int sendframe __ARGS((struct ax25_cb *axp,int cmdrsp,int ctl,struct mbuf *data));
  304. void axnl3 __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  305.     char *dest,struct mbuf *bp,int mcast));
  306.  
  307. /* In ax25cmd.c: */
  308. void st_ax25 __ARGS((struct ax25_cb *axp));
  309.  
  310. /* In axhdr.c: */
  311. struct mbuf *htonax25 __ARGS((struct ax25 *hdr,struct mbuf *data));
  312. int ntohax25 __ARGS((struct ax25 *hdr,struct mbuf **bpp));
  313.  
  314. /* In axlink.c: */
  315. void getlqentry __ARGS((struct lqentry *ep,struct mbuf **bpp));
  316. void getlqhdr __ARGS((struct lqhdr *hp,struct mbuf **bpp));
  317. void logsrc __ARGS((struct iface *iface,char *addr));
  318. void logdest __ARGS((struct iface *iface,char *addr));
  319. char *putlqentry __ARGS((char *cp,char *addr,int32 count));
  320. char *putlqhdr __ARGS((char *cp,int16 version,int32 ip_addr));
  321. struct lq *al_lookup __ARGS((struct iface *ifp,char *addr,int sort));
  322.  
  323. /* In ax25user.c: */
  324. int ax25val __ARGS((struct ax25_cb *axp));
  325. int disc_ax25 __ARGS((struct ax25_cb *axp));
  326. int kick_ax25 __ARGS((struct ax25_cb *axp));
  327. struct ax25_cb *open_ax25 __ARGS((struct iface *,char *,char *,
  328.     int,int16,
  329.     void (*) __ARGS((struct ax25_cb *,int)),
  330.     void (*) __ARGS((struct ax25_cb *,int)),
  331.     void (*) __ARGS((struct ax25_cb *,int,int)),
  332.     int user));
  333. struct mbuf *recv_ax25 __ARGS((struct ax25_cb *axp,int16 cnt));
  334. int reset_ax25 __ARGS((struct ax25_cb *axp));
  335. int send_ax25 __ARGS((struct ax25_cb *axp,struct mbuf *bp,int pid));
  336.  
  337. /* In ax25subr.c: */
  338. int addreq __ARGS((char *a,char *b));
  339. struct ax25_cb *cr_ax25 __ARGS((char *local,char *remote));
  340. void del_ax25 __ARGS((struct ax25_cb *axp));
  341. struct ax25_cb *find_ax25 __ARGS((char *local,char *remote));
  342. char *pax25 __ARGS((char *e,char *addr));
  343. int setcall __ARGS((char *out,char *call));
  344.  
  345. /* In socket.c: */
  346. void beac_input __ARGS((struct iface *iface,char *src,struct mbuf *bp));
  347. void s_arcall __ARGS((struct ax25_cb *axp,int cnt));
  348. void s_ascall __ARGS((struct ax25_cb *axp,int old,int new));
  349. void s_atcall __ARGS((struct ax25_cb *axp,int cnt));
  350.  
  351. #endif    /* _AX25_H */
  352.